package lt.mockos.app.client.cpu.hw.descriptor;

import lt.mockos.app.client.cpu.hw.type.ProcessPriority;
import lt.mockos.app.client.cpu.hw.type.ProcessStatus;
import lt.mockos.app.client.cpu.hw.type.ProcessType;
import lt.mockos.app.client.cpu.hw.type.Registers;

public class ProcessDescriptor implements Descriptor {

    private int ID;
    private String title;
    private ProcessStatus status;
    private ResourceDescriptor askedResource;
    private ProcessPriority priority;
    private ProcessType type;
    private ProcessDescriptor parent;
    private Registers savedRegisters;

    public ProcessDescriptor(String title, ProcessPriority priority, ProcessDescriptor parent, ProcessType type) {
        super();
        this.title = title;
        this.priority = priority;
        this.parent = parent;
        this.setType(type);

        status = ProcessStatus.BLOCK;
    }

    public ProcessStatus getStatus() {
        return status;
    }

    public void setStatus(ProcessStatus status) {
        this.status = status;
    }

    public String getTitle() {
        return title;
    }

    public ProcessPriority getPriority() {
        return priority;
    }

    @Override
    public ProcessDescriptor getParent() {
        return parent;
    }

    @Override
    public DescriptorType getDescriptorType() {
        return DescriptorType.PROCESS;
    }

    @Override
    public int getID() {
        return ID;
    }

    public void setID(int iD) {
        ID = iD;
    }

    public ResourceDescriptor getAskedResource() {
        return askedResource;
    }

    public void setAskedResource(ResourceDescriptor askedResource) {
        this.askedResource = askedResource;
    }

    public Registers getSavedRegisters() {
        return savedRegisters;
    }

    public void setSavedRegisters(Registers savedRegisters) {
        this.savedRegisters = savedRegisters;
    }

    public ProcessType getType() {
        return type;
    }

    public void setType(ProcessType type) {
        this.type = type;
    }

    @Override
    public String toString() {
        return "P:" + ID + "." + title + "." + status.name() + "." + (askedResource != null ? askedResource.getID() + "" : ".") + "." + priority.name() + "." + type.name() + "."
                + (parent != null ? parent.getID() + "" : ".") + "." + (savedRegisters != null ? savedRegisters.toString() : ".");
    }
}
